import { currentState } from "./index.js";
import { emit } from "./utils/scoket.js";

export interface State {
  roleName: string;
  roleSpeed: number;
  role?: "p1" | "p2";
  moveFrequency: number;
  bulletSpeed: number;
  bulletMove: number;
  bulletFrequency: number;
  hp: number;
  direction?: 1 | -1;
  stop: boolean;
}

//角色状态
export const state: State = {
  roleName: "我",
  //血量
  hp: 10,
  //移动速度
  roleSpeed: 30,
  //移动频率
  moveFrequency: 20,
  //子弹移动距离
  bulletSpeed: 30,
  //子弹移动频率
  bulletMove: 20,
  //子弹发射频率
  bulletFrequency: 2,
  //停止自己的行为
  stop: false,
};

//指令
export const instrction = {
  wwssadadbaba() {
    state.hp = 30;
    if (currentState.role === "p1") emit.p1("/getState", state);
    if (currentState.role === "p2") emit.p2("/getState", state);
  },
  bulletspeed() {
    state.bulletMove = 150;
  },
  bulletfrequency() {
    state.bulletFrequency = 10;
  },
};

export interface Options {
  barrageColor: string;
  barrageSpeed: number;
  bgc: string;
  type: string;
  role?: string; //服务器收到属性
  str?: string; //服务器收到属性
}
export const options: Options = {
  barrageColor: "#4fc1ff",
  bgc: "",
  barrageSpeed: 30,
  type: "rolling",
};
